﻿using System;
using System.Html;
using Quicklight.Web.Html;
using jQueryApi;

namespace Quicklight.Web.Razor {

   /// <summary>
   /// Does the binding on behalf of a declarative binding of a Validation to the inner content of an element
   /// For example <div style="color:Red;">@Binding(ViewModel.X.Validation)</div>
   /// </summary>
   public class ValidationContentBinder : ContentBinder {
      private Validation validation;

      /// <summary>
      /// Constructs a ValidationContentBinder for binding the Validation to the inner content of an element
      /// </summary>
      /// <param name="validation">Validation to bind to the inner content of an element</param>
      public ValidationContentBinder(Validation validation) {
            this.validation = validation;
      }

      /// <summary>
      /// Bind method does the actual binding of the Validation to the inner content of the specified element
      /// </summary>
      /// <param name="element">Element with which the binding must occur</param>
      protected override void Bind(Element element) {
         element.Bind(validation);

         jQueryObject jQueryObject = jQuery.FromElement(element);
         jQueryObject.Text(validation.Message);
      }
   }
}
